<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-13 19:19:19
 * @LastEditTime: 2019-08-13 21:44:49
 * @LastEditors: Please set LastEditors
 -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    账号<input type="text" id="name" /><span id="in"></span> 密码<input
      type="password"
      name=""
      id="password"
    />
    <input type="button" value="注册" />
  </body>
  <script src="../common.js"></script>
  <script>
    (function() {
      var name = document.getElementById("name");
      let inf = document.getElementById("in");
      name.onblur = () => {
        ajax({
          type: "post",
          data: {
            username: name.value
          },
          url: "api/naem.php",
          success: function(str) {
            if (str == "yes") {
              inf.innerHTML = "可以注册";
            } else {
              inf.innerHTML = "用户名太受欢迎啦。请换一个";
            }
          }
        });
      };
      // name.onblur = () => {
      //     let xhr = new XMLHttpRequest;
      //     let url = 'api/naem.php';
      //     xhr.open('post', url, true);
      //     let data = 'name=' + name.value;
      //     xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
      //     xhr.send(data);
      //     xhr.onreadystatechange = () => {
      //         if (xhr.readyState == 4 && xhr.status == 200) {
      //             let data = xhr.responseText;
      //             if (data == 'yes') {
      //                 inf.innerHTML = 'ke';

      //             } else {
      //                 inf.innerHTML = 'bu';
      //             }
      //         }
      //     }
      // }
    })();
  </script>
</html>
